FROM centos:7

WORKDIR /home

# 更新镜像源，安装相关依赖
COPY tsinghua7.repo /etc/yum.repos.d/CentOS-Base.repo
RUN yum makecache
RUN yum -y install openssl openssl-devel zlib-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel \
    gcc gcc-c++ autoconf automake make epel-release java-1.8.0-openjdk*

# 安装Python3，替换为清华镜像
COPY Python-3.7.3.tgz Python-3.7.3.tgz
RUN tar -zxvf Python-3.7.3.tgz && cd Python-3.7.3 && ./configure --prefix=/usr/local/python3 --with-ssl && make && make install
RUN rm -f /usr/bin/python && ln -s /usr/local/python3/bin/python3 /usr/bin/python
RUN rm -f /usr/bin/pip && ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
COPY get-pip.py get-pip.py
RUN python get-pip.py -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

# 安装Nginx
COPY nginx-1.14.0.tar.gz nginx-1.14.0.tar.gz
COPY nginx-rtmp-module.tar.gz nginx-rtmp-module.tar.gz
RUN tar -zxvf nginx-1.14.0.tar.gz && tar -zxvf nginx-rtmp-module.tar.gz
RUN cd nginx-1.14.0 && \
    ./configure --with-stream --with-http_stub_status_module --with-http_ssl_module \
    --add-module=/home/nginx-rtmp-module \
    && make && make install
COPY nginx.conf /usr/local/nginx/conf/nginx.conf
COPY mime.types /usr/local/nginx/conf/mime.types
RUN mkdir /tmp/hls

# 安装FFmpeg
COPY nasm-2.14.tar.gz nasm-2.14.tar.gz
COPY yasm-1.3.0.tar.gz yasm-1.3.0.tar.gz
RUN tar -zxvf nasm-2.14.tar.gz && cd nasm-2.14 && ./configure && make && make install
RUN tar -zxvf yasm-1.3.0.tar.gz && cd yasm-1.3.0 && ./configure && make && make install
COPY x264 x264
RUN cd x264 && ./configure --enable-static --enable-shared && make && make install
COPY ffmpeg-4.2.1.tar.gz ffmpeg-4.2.1.tar.gz
RUN tar -zxvf ffmpeg-4.2.1.tar.gz && cd ffmpeg-4.2.1 && ./configure --enable-gpl --enable-libx264 && make && make install
RUN sed -i '1a\/usr/local/lib' /etc/ld.so.conf && ldconfig

ENV PATH=$PATH:/usr/local/nginx/sbin

EXPOSE 8888
EXPOSE 1935

CMD ["nginx","-g","daemon off;"]